import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

//路由规则对象
//路由模块化
//引入组件
import notfound from '@/views/error/notfound.vue'
//引入路由规则的各个模块
import homeRoute from './modules/home'
import userSpace from './modules/user-space'
import fenleiRoute from './modules/fenlei'
import cookbookRoute from './modules/cookbook'
import caipuRoute from './modules/caipu'


const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  ...homeRoute,
  ...fenleiRoute,
  ...caipuRoute,
  ...cookbookRoute,
  ...userSpace,
  {
    path: '*',
    component: notfound
  }
]

let originPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (path) {
  originPush.call(this, path).catch(err => err)
}

const router = new VueRouter({
  //更改模式 hash history
  mode: 'history',
  //基于
  base: process.env.BASE_URL,
  //路由规则 数组 对象
  routes
})

export default router
